//package com.matt.foundation.utils.export;
//
//import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON;
//import com.matt.foundation.utils.CopyUtils;
//import com.matt.foundation.utils.DateUtil;
//import com.matt.foundation.utils.ImgUtil;
//import com.matt.foundation.utils.export.meta.BMI;
//import com.matt.foundation.utils.export.meta.BMI2;
//import com.matt.foundation.utils.export.meta.ValueP;
//import org.apache.commons.lang3.StringUtils;
//import org.joda.time.DateTime;
//import org.joda.time.Interval;
//import org.joda.time.PeriodType;
//
//import java.awt.image.BufferedImage;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//public class HealthReportUtil {
//
//    private static boolean compare(double value1, char operator, double value2){
//        switch (operator){
//            case '<':
//                return value1 < value2;
//            case '>':
//                return value1 > value2;
//            case 'G':
//                return value1 >= value2;
//            case 'L':
//                return value1 < value2;
//            default:
//                return value1 == value2;
//        }
//    }
//    private static boolean judgeValueP (int month, String gender, String type, double value, int line, char symbol) {
//
//        gender = gender.equals("女")?"girl":"boy";
//
//        Map valueP = CopyUtils.transBean2Map(new ValueP());
//
//        double mon[] = (double[]) valueP.get("month");
//
//        String line_key = gender + '_'+ type + "_p" + line;
//        double[] line_values = (double[])valueP.get(line_key);
//
//        for ( int i = 0 ; i < mon.length; i++) {
//            if (month == mon[i] || (month < mon[i] && i == 0)) {
//                double cv = line_values[i];
//                return compare(value , symbol , cv);
//            }
//
//            if (month < mon[i]) {
//                double cv1 = line_values[i-1];
//                double cv = line_values[i];
//
//                double v = cal(mon[i-1], cv1, mon[i], cv, month);
//                return compare(value , symbol , v);
//            }
//        }
//
//        return false;
//    }
//
//    private static double cal(double start_m, double start_v, double end_m, double end_v, double target_m) {
//
//        return start_v + (end_v - start_v) / (end_m - start_m) * (target_m - start_m);
//
//    }
//
//    private static boolean judgeValueBMI ( double height, String gender, double weight, int line, char symbol) {
//        Map BMI = CopyUtils.transBean2Map(new BMI());
//
//        gender = gender.equals("女")?"girl":"boy";
//
//        String key = gender + "_height";
//        double[] heightBMI = (double[]) BMI.get(key);
//        ;
//        double[] values = (double[]) BMI.get(gender + "_weight_p" + line);
//
//        for (int i = 0; i < heightBMI.length; i ++) {
//            if (height == heightBMI[i] || (height < heightBMI[i] && i == 0)) {
//                double cv = values[i];
//                return compare(weight , symbol , cv);
//            }
//
//            if (height < heightBMI[i]) {
//                double cv1 = values[i-1];
//                double cv = values[i];
//
//                double v = cal(heightBMI[i-1], cv1, heightBMI[i], cv, height);
//                return compare(weight , symbol , v);
//            }
//        }
//
//        return false;
//    }
//
//
//    private static boolean judgeValueSD ( double height, String gender, double weight, int line, char symbol) {
//        double[] heightX = BMI2.height;
//
//        Map BMI2 = CopyUtils.transBean2Map(new BMI2());
//
//        gender = gender.equals("女")?"girl":"boy";
//
////        String jsonStr1 = JSON.toJSONString(BMI2);
////        System.out.println("BMI2_json:\n" + jsonStr1);
//
//        String line_key = gender + "_sd" + line;
//        double[] line_values = (double[]) BMI2.get(line_key);
//
//        for (int i = 0; i < heightX.length; i ++) {
//            if (height == heightX[i] || (height < heightX[i] && i == 0)) {
//                double cv = line_values[i];
//                return compare(weight, symbol, cv);
//            }
//
//            if (height < heightX[i]) {
//                double cv1 = line_values[i-1];
//                double cv = line_values[i];
//
//                double v = cal(heightX[i-1], cv1, heightX[i], cv, height);
//                return compare(weight , symbol , v);
//            }
//        }
//        return false;
//    }
//
//    public static String readablePercent(String result){
//        String[] values = {"<P3", "P3-P10", "P10-P20", "P20-P50", "P50-P80","P80-P97",">P97"};
//        String[] readables = {"极低", "低", "中下", "中", "中上", "高", "极高"};
//
//        for(int i = 0; i < values.length; i++){
//            if(values[i].equals(result)){
//                return readables[i] + "(" + result + ")";
//            }
//        }
//
//        return result;
//    }
//
//    public static String calcHeightPercent(int month, String gender, double height){
//        String heightPercent = null;
//        if(judgeValueP(month, gender, "height", height, 3, '<')){
//            heightPercent = "<P3";
//        }else if(judgeValueP(month, gender, "height", height, 10, '<')){
//            heightPercent = "P3-P10";
//        }else if(judgeValueP(month, gender, "height", height, 20, '<')){
//            heightPercent = "P10-P20";
//        }else if(judgeValueP(month, gender, "height", height, 50, '<')){
//            heightPercent = "P20-P50";
//        }else if(judgeValueP(month, gender, "height", height, 80, '<')){
//            heightPercent = "P50-P80";
//        }else if(judgeValueP(month, gender, "height", height, 97, '<')){
//            heightPercent = "P80-P97";
//        }else{
//            heightPercent = ">P97";
//        }
//        return heightPercent;
//    }
//
//    public static String calcWeightPercent(int month, String gender, double weight) {
//        String weightPercent = null;
//
//        if (judgeValueP(month, gender, "weight", weight, 3, '<')) {
//            weightPercent = "<P3";
//        } else if (judgeValueP(month, gender, "weight", weight, 10, '<')) {
//            weightPercent = "P3-P10";
//        } else if (judgeValueP(month, gender, "weight", weight, 20, '<')) {
//            weightPercent = "P10-P20";
//        } else if (judgeValueP(month, gender, "weight", weight, 50, '<')) {
//            weightPercent = "P20-P50";
//        } else if (judgeValueP(month, gender, "weight", weight, 80, '<')) {
//            weightPercent = "P50-P80";
//        } else if (judgeValueP(month, gender, "weight", weight, 97, '<')) {
//            weightPercent = "P80-P97";
//        } else {
//            weightPercent = ">P97";
//        }
//
//        return weightPercent;
//    }
//
//
//    public static String calcBMIPercent(double weight, double height , String gender) {
//        String bmiPercent = null;
//
//        if (judgeValueBMI(height, gender, weight, 3, '<')) {
//            bmiPercent = "<P3";
//        } else if (judgeValueBMI(height, gender, weight, 10, '<')) {
//            bmiPercent = "P3-P10";
//        } else if (judgeValueBMI(height, gender, weight, 20, '<')) {
//            bmiPercent = "P10-P20";
//        } else if (judgeValueBMI(height, gender, weight, 50, '<')) {
//            bmiPercent = "P20-P50";
//        } else if (judgeValueBMI(height, gender, weight, 80, '<')) {
//            bmiPercent = "P50-P80";
//        } else if (judgeValueBMI(height, gender, weight, 97, '<')) {
//            bmiPercent = "P80-P97";
//        } else {
//            bmiPercent = ">P97";
//        }
//
//        return bmiPercent;
//    }
//
//    public Map heightWeightLines(){
//        Map BMI = CopyUtils.transBean2Map(new BMI());
//        return BMI;
//    }
//
//    public static String heightConclusionSimple(String name, String gender, double height, int month ){
//
//        String heightPercent = calcHeightPercent(month, gender, height );
//
//        String conclusion = name + "宝宝";
//
//        if(judgeValueP(month, gender, "height", height, 3, '<')){
//            conclusion += "为重度发育不良，需进一步调整饮食，增强锻炼，并咨询专业医生。";
//        }else if(judgeValueP(month, gender, "height", height, 10, '<')){
//            conclusion += "为轻度发育不良，需进一步调整饮食，增强锻炼。";
//        }else if(judgeValueP(month, gender, "height", height, 50, '<')){
//            conclusion += "有极轻微发育不良迹象，需调整饮食，增强锻炼。";
//        }else{
//            conclusion += "身高发育正常！";
//        }
//
//        return conclusion;
//    }
//
//    public static String weightConclusionSimple(String name, String gender, double height, double weight, int month ){
//        String conclusion = name + "宝宝";
//
//        if(judgeValueP(month, gender, "weight", weight, 3, '<') && judgeValueBMI(height, gender, weight, 3, '<')){
//            conclusion += "为重度营养不良，需进一步调整饮食，增强锻炼。";
//        }else if(judgeValueP(month, gender, "weight", weight, 10, '<') && judgeValueBMI(height, gender, weight, 10, '<')){
//            conclusion += "为轻度营养不良，需进一步调整饮食，增强锻炼。";
//        }else if(judgeValueP(month, gender, "weight", weight, 50, 'G') && judgeValueBMI(height, gender, weight, 50, 'G')){
//            if(judgeValueSD(height, gender, weight, 3, 'G')){
//                conclusion += "为中重度肥胖，需进一步调整饮食，增强锻炼！";
//            }else if(judgeValueSD(height, gender, weight, 2, 'G')){
//                conclusion += "为轻度肥胖，需进一步调整饮食，增强锻炼！";
//            }else if(judgeValueSD(height, gender, weight, 1, 'G')){
//                conclusion += "为超重，需进一步调整饮食，增强锻炼！";
//            }else{
//                conclusion += "身体发育正常！";
//            }
//        }else{
//            conclusion += "身体发育正常！";
//        }
//
//        return conclusion;
//    }
//
//    public static String heightConclusion(String name, String gender, double height, int month ){
//
//        String heightPercent = calcHeightPercent(month, gender, height );
//
//        String conclusion = "实测身长" +String.format("%.2f", height)+  "cm，按年龄测身长的百分位数为" + heightPercent  + "。如年龄身长曲线图所示，"
//                + heightConclusionSimple(name, gender, height, month);
//
//        return conclusion;
//    }
//
//    public static String weightConclusion(String name, String gender, double height, double weight, int month ){
//
//        String weightPercent = calcWeightPercent(month, gender, weight);
//        String bmiPercent = calcBMIPercent(weight, height, gender);
//
//        String conclusion = "实测体重" +String.format("%.2f", weight)+  "kg，按年龄测体重的百分位数为" + weightPercent
//                + "，按身长测体重的百分位数为" + bmiPercent
//                + "。如年龄体重曲线图所示，"
//                + weightConclusionSimple(name, gender, height, weight, month);
//
//        return conclusion;
//    }
//
//
//    public static String fullConclusion(String name, String gender, double height, double weight, int month ){
//
//        String heightPercent = calcHeightPercent(month, gender, height );
//        String weightPercent = calcWeightPercent(month, gender, weight);
//        String bmiPercent = calcBMIPercent(weight, height, gender);
//
//        String conclusion = "从上述三个图表可以看到" + name
//                + "宝宝按年龄测身长的百分位数为" + heightPercent
//                + "，按年龄测体重的百分位数为" + weightPercent
//                + "，按身长测体重的百分位数为" + bmiPercent
//                + "，综合上述三个数据可以得出"
//                + weightConclusionSimple(name, gender, height, weight, month);
//
//        return conclusion;
//    }
//
//
//    public static String encodedHeightChart(String gender, float month, float height){
//
//        String[] heightLineNames = HealthReportUtil.heightLineNames(gender);
//        double[][] heightLineValues = HealthReportUtil.heightLineValues(gender);
//        BufferedImage heightChart = LineChartXY.createChartBufferedImage(null, heightLineNames, heightLineValues,
//                "月","cm", month, height);
//
//        String heightImg = ImgUtil.getBase64(heightChart);
//
//        return heightImg;
//    }
//
//    public static String encodedWeightChart(String gender, float month, float weight){
//        String[] weightLineNames = HealthReportUtil.weightLineNames(gender);
//        double[][] weightLineValues = HealthReportUtil.weightLineValues(gender);
//        BufferedImage weightChart = LineChartXY.createChartBufferedImage(null, weightLineNames, weightLineValues,
//                "月","kg", month, (float) weight);
//
//        String weightImg = ImgUtil.getBase64(weightChart);
//
//        return weightImg;
//    }
//
//    public static String[] heightLineNames(String gender){
//        String[] ret = {"P3", "P20", "P50", "P80", "P97"};
//        return ret;
//    }
//
//    public static double[][] heightLineValues(String gender) {
//        if (gender.equals("男")) {
//            double[][] ret = {
//                    {52.50, 56.40, 60.20, 62.10, 63.80, 65.50, 68.10, 70.10, 72.80, 76.50, 79.00, 81.50, 85.20, 89.30, 93.00, 96.40, 100.30, 103.60, 105.30, 108.40, 112.20},
//                    {54.40, 58.50, 62.00, 64.10, 66.00, 67.70, 70.50, 73.00, 75.50, 79.50, 81.70, 85.00, 88.00, 93.30, 96.80, 100.00, 104.20, 107.20, 110.70, 113.20, 118.10},
//                    {56.00, 60.30, 63.50, 66.00, 67.50, 69.50, 73.00, 75.20, 77.60, 81.40, 83.80, 87.95, 90.50, 95.60, 99.60, 103.30, 107.70, 110.60, 114.30, 117.30, 122.50},
//                    {58.00, 62.00, 65.20, 67.60, 69.60, 71.20, 74.60, 77.30, 80.00, 83.60, 86.10, 90.40, 93.60, 98.10, 102.70, 106.50, 110.90, 114.70, 118.60, 120.70, 126.50},
//                    {60.50, 64.00, 67.30, 69.50, 72.00, 74.00, 76.70, 79.40, 83.50, 86.90, 89.00, 93.50, 97.00, 101.90, 107.60, 110.40, 115.40, 119.20, 123.60, 125.50, 132.40},
//            };
//            return ret;
//        } else {
//            double[][] ret = {
//                    {52.60, 56.30, 59.30, 61.20, 63.70, 64.90, 68.20, 70.70, 73.00, 76.50, 79.10, 82.30, 85.20, 89.90, 94.50, 97.30, 100.60, 103.60, 108.00, 110.75, 114.40},
//                    {53.40, 57.15, 60.20, 62.50, 64.50, 65.80, 69.10, 71.80, 74.20, 77.80, 80.20, 83.90, 86.60, 91.20, 95.80, 99.50, 102.60, 105.60, 109.80, 112.70, 116.40},
//                    {55.00, 58.70, 61.80, 64.10, 66.00, 67.80, 71.10, 74.00, 76.30, 80.20, 82.40, 86.10, 89.00, 94.10, 98.90, 102.60, 106.00, 109.50, 113.20, 116.50, 120.80},
//                    {57.10, 60.50, 63.70, 66.00, 68.00, 69.50, 73.10, 75.90, 78.50, 82.50, 85.00, 88.40, 92.00, 96.75, 101.50, 105.70, 109.70, 112.70, 116.70, 120.50, 125.30},
//                    {59.60, 62.60, 66.00, 68.00, 69.90, 72.10, 75.60, 78.30, 81.60, 85.70, 87.70, 92.50, 95.20, 100.00, 106.20, 110.40, 114.00, 117.30, 121.70, 125.00, 130.00}
//            };
//            return ret;
//        }
//    }
//
//    public static String[] weightLineNames(String gender){
//        String[] ret = {"P3", "P20", "P50", "P80", "P97"};
//        return ret;
//    }
//
//    public static double[][] weightLineValues(String gender){
//        if(gender.equals("男")) {
//            double[][] ret = {
//                    {3.98, 5.00, 5.95, 6.45, 6.82, 7.28, 7.68, 8.13, 8.53, 9.20, 9.80, 10.30, 11.00, 11.80, 12.50, 13.60, 14.70, 15.10, 15.96, 16.95, 18.21},
//                    {4.40, 5.65, 6.50, 7.16, 7.60, 8.01, 8.60, 9.00, 9.40, 10.14, 10.60, 11.45, 12.00, 13.20, 14.18, 15.00, 16.10, 17.00, 18.05, 19.05, 20.66},
//                    {4.90, 6.19, 7.12, 7.85, 8.25, 8.80, 9.34, 9.90, 10.29, 11.10, 11.45, 12.40, 13.10, 14.20, 15.50, 16.40, 17.75, 18.90, 20.06, 21.10, 23.50},
//                    {5.45, 6.77, 7.75, 8.60, 9.05, 9.70, 10.02, 10.80, 11.30, 12.01, 12.55, 13.60, 14.30, 15.50, 17.00, 18.30, 19.82, 21.50, 23.15, 24.24, 27.45},
//                    {6.30, 7.80, 8.60, 9.70, 10.40, 10.74, 11.36, 11.95, 12.80, 13.25, 13.85, 15.20, 16.35, 18.20, 20.15, 21.30, 23.90, 25.90, 29.00, 30.10, 33.70},
//            };
//            return ret;
//        }else{
//            double[][] ret = {
//                    {3.66, 4.70, 5.40, 6.00, 6.31, 6.60, 7.24, 7.55, 8.20, 8.50, 9.05, 9.90, 10.30, 11.15, 12.20, 13.00, 13.85, 14.60, 15.70, 16.15, 17.23},
//                    {3.95, 5.00, 5.78, 6.40, 6.70, 7.00, 7.70, 8.27, 8.55, 9.10, 9.65, 10.40, 10.95, 12.00, 13.05, 14.01, 14.70, 15.50, 16.60, 17.50, 18.62},
//                    {4.11, 5.20, 6.00, 6.65, 6.99, 7.30, 8.00, 8.60, 8.87, 9.48, 10.00, 10.85, 11.40, 12.45, 13.60, 14.50, 15.40, 16.20, 17.50, 18.58, 19.40},
//                    {4.56, 5.68, 6.55, 7.20, 7.60, 8.05, 8.80, 9.30, 9.75, 10.35, 10.82, 11.75, 12.50, 13.50, 14.90, 15.95, 17.03, 18.00, 19.30, 20.40, 22.00},
//                    {5.10, 6.30, 7.24, 7.90, 8.38, 8.84, 9.63, 10.17, 10.70, 11.38, 11.88, 12.80, 13.70, 15.02, 16.37, 17.66, 18.95, 20.30, 21.70, 23.35, 25.30},
//                    {5.81, 7.15, 8.00, 8.75, 9.50, 9.90, 10.62, 11.50, 12.05, 12.66, 13.35, 14.40, 15.91, 17.37, 19.08, 20.80, 23.00, 23.42, 25.10, 27.30, 30.10},
//            };
//            return ret;
//        }
//    }
//
//    public static void main(String[] args) {
//        //String conclusion = fullConclusion("可可", "girl", 90, 12, 18);
//
//        String weight = "160";
//        String height = "120";
//
//        Map<String,String > resultMap = new HashMap<>();
//        String g = "boy";
//        DateTime now = DateTime.now();
//        Date birthday = DateTime.parse("2017-04-08").toDate();
//        Interval interval = new Interval(birthday.getTime(),now.toDate().getTime());
//        int month = interval.toPeriod(PeriodType.months()).getMonths();
//
//        if(org.apache.commons.lang3.StringUtils.isNotBlank(weight)){
//            Double w = Double.parseDouble(weight);
//            String wResult = HealthReportUtil.calcHeightPercent(month,g,w);
//            resultMap.put("wResult",wResult);
//        }
//
//        if(org.apache.commons.lang3.StringUtils.isNotBlank(height)){
//            Double h = Double.parseDouble(height);
//            String hResult = HealthReportUtil.calcHeightPercent(month,g,h);
//            resultMap.put("hResult",hResult);
//        }
//
//        System.out.println(resultMap);
//    }
//
//
//    public static Map bmiInfo( String name, Integer gender, String birthday, String weight, String height ) {
//
//        Map result = new HashMap();
//
//        String genderStr = (gender == 0) ? "女" : "男";
//
//        if (org.apache.commons.lang3.StringUtils.isNotBlank(birthday)) {
//
//            float actualMonth = (float) DateUtil.betweenMonthsV2(new Date(), DateUtil.parseToDate(birthday));
//            result.put("actualMonth", actualMonth);
//
//            double h = 0;
//            double w = 0;
//            if (org.apache.commons.lang3.StringUtils.isNotBlank(weight) && StringUtils.isNotBlank(height)) {
//                h = Double.parseDouble(height);
//                w = Double.parseDouble(weight);
//
//                String heightConclusion = HealthReportUtil.heightConclusion(name, genderStr, h, (int) actualMonth);
//                String weightConclusion = HealthReportUtil.weightConclusion(name, genderStr, h, w, (int) actualMonth);
//                result.put("heightConclusion", heightConclusion);
//                result.put("weightConclusion", weightConclusion);
//            }
//        }
//        String[] heightLineNames = HealthReportUtil.heightLineNames(genderStr);
//        double[][] heightLineValues = HealthReportUtil.heightLineValues(genderStr);
//
//        String[] weightLineNames = HealthReportUtil.weightLineNames(genderStr);
//        double[][] weightLineValues = HealthReportUtil.weightLineValues(genderStr);
//
//        result.put("heightLineNames", heightLineNames);
//        result.put("heightLineValues", heightLineValues);
//        result.put("weightLineNames", weightLineNames);
//        result.put("weightLineValues", weightLineValues);
//
//        return result;
//    }
//}
